package org.fiel.torque;


import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.apache.torque.Torque;
import org.apache.torque.TorqueException;
import org.apache.torque.om.BaseObject;
import org.apache.torque.om.ComboKey;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.om.SimpleKey;
import org.apache.torque.om.StringKey;
import org.apache.torque.om.Persistent;
import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;



      

/**
 * You should not use this class directly.  It should not even be
 * extended all references should be to Tipo
 */
public abstract class BaseTipo extends BaseObject
{
    /** The Peer class */
    private static final TipoPeer peer =
        new TipoPeer();

        
    /** The value for the id field */
    private Integer id;
      
    /** The value for the descripcion field */
    private String descripcion;
      
    /** The value for the codigo field */
    private String codigo;
  
            
    /**
     * Get the Id
     *
     * @return Integer
     */
    public Integer getId()
    {
        return id;
    }

        
    /**
     * Set the value of Id
     *
     * @param v new value
     */
    public void setId(Integer v) 
    {
    
                  if (!ObjectUtils.equals(this.id, v))
              {
            this.id = v;
            setModified(true);
        }
    
        }
          
    /**
     * Get the Descripcion
     *
     * @return String
     */
    public String getDescripcion()
    {
        return descripcion;
    }

        
    /**
     * Set the value of Descripcion
     *
     * @param v new value
     */
    public void setDescripcion(String v) 
    {
    
                  if (!ObjectUtils.equals(this.descripcion, v))
              {
            this.descripcion = v;
            setModified(true);
        }
    
        }
          
    /**
     * Get the Codigo
     *
     * @return String
     */
    public String getCodigo()
    {
        return codigo;
    }

        
    /**
     * Set the value of Codigo
     *
     * @param v new value
     */
    public void setCodigo(String v) 
    {
    
                  if (!ObjectUtils.equals(this.codigo, v))
              {
            this.codigo = v;
            setModified(true);
        }
    
        }
  
    
     
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     *
     * @throws Exception
     */
    public void save() throws Exception
    {
          if (isModified())
        {
            if (isNew())
            {
                TipoPeer.doInsert((Tipo) this);
                setNew(false);
            }
            else
            {
                TipoPeer.doUpdate((Tipo) this);
            }
        }
      }

    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
       *
     * @param dbName
     * @throws TorqueException
     */
    public void save(String dbName) throws TorqueException
    {
        Connection con = null;
          if (isModified())
        {
            try
            {
                con = Torque.getConnection(dbName);
                if (isNew())
                {
                    TipoPeer
                        .doInsert((Tipo) this, con);
                    setNew(false);
                }
                else
                {
                    TipoPeer
                        .doUpdate((Tipo) this, con);
                }
            }
            finally
            {
                Torque.closeConnection(con);
            }
        }
      }

      /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.  This method
     * is meant to be used as part of a transaction, otherwise use
     * the save() method and the connection details will be handled
     * internally
     *
     * @param con
     * @throws TorqueException
     */
    public void save(Connection con) throws TorqueException
    {
  
            // If this object has been modified, then save it to the database.
            if (isModified())
            {
                if (isNew())
                {
                    TipoPeer.doInsert((Tipo) this, con);
                    setNew(false);
                }
                else
                {
                    TipoPeer.doUpdate((Tipo) this, con);
                }
                }

        }

        
      /**
     * Set the PrimaryKey using ObjectKey.
     *
     * @param key id ObjectKey
     */
    public void setPrimaryKey(ObjectKey key)
        
    {
            setId(new Integer(((NumberKey) key).intValue()));
        }

    /**
     * Set the PrimaryKey using a String.
     *
     * @param key
     */
    public void setPrimaryKey(String key) 
    {
            setId(new Integer(key));
        }

  
    /**
     * returns an id that differentiates this object from others
     * of its class.
     */
    public ObjectKey getPrimaryKey()
    {
          return SimpleKey.keyFor(getId());
      }
 

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
       */
      public Tipo copy() throws TorqueException
    {
        return copyInto(new Tipo());
    }
  
    protected Tipo copyInto(Tipo copyObj) throws TorqueException
    {
          copyObj.setId(id);
          copyObj.setDescripcion(descripcion);
          copyObj.setCodigo(codigo);
  
                    copyObj.setId((Integer)null);
                        
          return copyObj;
    }

    /**
     * returns a peer instance associated with this om.  Since Peer classes
     * are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     */
    public TipoPeer getPeer()
    {
        return peer;
    }


    public String toString()
    {
        StringBuffer str = new StringBuffer();
        str.append("Tipo:\n");
        str.append("Id = ")
               .append(getId())
             .append("\n");
        str.append("Descripcion = ")
               .append(getDescripcion())
             .append("\n");
        str.append("Codigo = ")
               .append(getCodigo())
             .append("\n");
        return(str.toString());
    }
}
